Beginning Programming Series VIII

Glossary & Appendix

© 2004, Brad Moore

author contact:

http://www.freewebz.com/lb-connection/

Home

Random Access Files

Liberty Simple Help2

Scrolling Background

Blood Presure Sim

Cellular Automata

Making Poker Game

Desktop Shortcuts2

Beginners Programming

Demos

Newsletter help

Index


Glossary

Standard Windows Controls - These are the GUI components that make up the basic windows interface. They include the buttons, textboxes, menus, tool-bars, drop-down lists, windows and many other graphic interface devices. Liberty Basic does not support all of these natively, but many are supported and other can be emulated. Here is a list of supported GUI components from the Liberty Basic Helpfile:

A BMPBUTTON is a clickable button that displays an image.  Bmpbuttons 
allow users to give a command to a program.

A BUTTON is a clickable button with a text label.  Buttons allow users 
to give a command to a program.

A CHECKBOX  is a small box that can be checked or unchecked by the 
user, or by the programmer.  It displays a text label.  Use a checkbox 
when giving a user multiple options from which to choose.

A COMBOBOX is a form of list.  It displays on the window as a small 
textbox with an arrow at the side.  When the user clicks the arrow, the 
list drops down and the user may make a selection.  Use a combobox when 
you want to give the user a list of choices, but there isn't much room 
on the window to display a list.

A GRAPHICBOX is a box that displays graphics, such as bitmap images, or 
drawn objects like circles and lines, or even text.  Use a graphicbox 
to give the user a graphic display, such as showing a bitmap image, 
rawing a graph or chart, or use it simply to add visual interest to a 
program.

A GROUPBOX consists of a label and a box.  The box can contain other 
controls, so that they may be grouped for easy identification.  
Radiobuttons within a groupbox function as a set.  To have multiple 
sets of radiobuttons in a window, place each set in its own groupbox.

A LISTBOX is a form of list.  It appears as a list of items in a box on 
the window.  The user may make a choice by clicking on an item in the 
list with the mouse.  If there are more items in the list than there is 
room in the listbox, the listbox will automatically add scrollbars.  
Use a listbox when you want to give the user a list of choices.

A MENU is a dropdown list of user commands that appears on a bar below 
the titlebar of a window.  The user clicks on an item contained in the 
dropdown list to give the window a command.

A POPUPMENU is a dropdown list of user commands that appears where the 
mouse is located when the popupmenu command is issued.  The user clicks 
on an item contained in the dropdown list to give the window a command.

A RADIOBUTTON is a small round box that can be clicked by the user.  It 
has a text label.  Radiobuttons function in groups.  When the user 
clicks a radiobutton, that button's circle is filled in and all other 
radiobuttons are cleared.  The programmer may set or unset a radiobutton 
in code also.  Use a radiobutton when a user must choose only one 
possibility from a group of possibilities.

A STATICTEXT is a simple text label used to give information to the user.  
The user cannot interact with a statictext control.

A TEXTBOX is a small box that contains text.  Text can be placed in the 
textbox by the programmer, or the user can type into the textbox.  Use a 
textbox to get a small amount of text input from the user, or to display 
a small amount of text.

A TEXTEDITOR is a large box with both horizontal and vertical scrollbars.  
Text can be placed in the texteditor by the programmer, or the user can 
type into the texteditor.  Use a texteditor to get a large amount of text 
input from the user, or to display a large amount of text.

FLUSH Command - The FLUSH command is used to make graphics draw to a graphics window/box "stick". Without it, any graphics draw will be lost should another windows object (like a menu or another window) cover the graphics window. In the background it commits memory to keep the graphics

drawn to the graphics window/box active when a window's RESIZE event occurs. This all happens in the background - Liberty Basic manages the "stickiness" or persistence of the graphics.

Message Window - this is a special type of dialog window that Windows implements as a part of its common controls GUI interface. It is used to communicate brief messages to the user. It can often have an associated icon to indicate importance. Liberty Basic supports the attention (Exclamation Icon) form of message box through the NOTICE function. The question (Question Mark Icon) form is supported through the CONFIRM function.

Development Methodology - This refers to the methods employed in the process

of developing code. It is the way a person works. Many software development

firms have invested heavily on specific defined methods that are taught in

classes and defined in big fat manuals. Most people who program often fall

into a pattern that is comfortable and efficient, and it is said that this

is their development methodology.

STR$() Function - This is a string function supported by Liberty Basic. It converts a numeric variable to a string. Here is what the Liberty Basic Helpfile tells us:

Description:

This function returns a string expressing the result of  numericExpression.  
In MBASIC, this function would always return a string representation of the 
expression and it would add a space in front of that string.  For example 
in MBASIC:

  print len(str$(3.14))

Would produce the number 5 (a space followed by 3.14 for a total of 5 
characters).

Liberty BASIC leaves it to you to decide whether you want that space or not.  
If you don't want it, then you need not do anything at all, and if you do 
want it, then this expression will produce the same result under Liberty BASIC:

  print len(" " + str$(3.14))

TIME$ Function - This is another Liberty Basic native function that can return the current system time. It appears to be a string function, but it will return numeric variables given certain arguments. The Liberty Basic Helpfile describes it this way:

Description:

This function returns a string representing the current time of the system 
clock in 24 hour format.  This function replaces the time$ variable used in 
QBasic.  See also DATE$( ).

  'this form of time$()                produces this format
  print time$()                          'time now as string "16:21:44"
  print time$("seconds")          'seconds since midnight as number 32314
  print time$("milliseconds")  'milliseconds since midnight as number 33221342
  print time$("ms")                 'milliseconds since midnight as number 33221342


Appendix A - The original Roll Dice Program

'** Roll Dice

'by Brad Moore - in the public domain

NOMAINWIN

WindowWidth = 362

WindowHeight = 226

UpperLeftX = 40

UpperLeftY = 40

STATICTEXT #main.wins, "Wins: 0", 240, 14, 100, 20

STATICTEXT #main.losses, "Losses: 0", 240, 36, 100, 20

STATICTEXT #main.info, "Beginning New Round - Click to start", 18, 112, 200, 20

STATICTEXT #main.point, "Point has not been made yet", 18, 134, 200, 20

button #main.quit, "Quit",[quit],UL, 240, 160, 100, 25

button #main.help, "Help",[help],UL, 240, 130, 100, 25

button #main.about, "About",[about],UL, 240, 100, 100, 25

button #main.new, "New Game",[new],UL, 240, 70, 100, 25

button #main.roll, "Start Round",[roll],UL, 16, 160, 212, 25

graphicbox #main.dice1, 20, 20, 80, 80

graphicbox #main.dice2, 140, 20, 80, 80

Open "Graphic Craps" for window_nf as #main

"trapclose [quit]"

'format graphics boxes

"down; fill white; up; flush"
"down; fill white; up; flush"
"backcolor black"
"backcolor black"

Wait

[quit]

close #main

END

[roll]

'roll a random number of times

playwave "dice01.wav", async

times = int(rnd(0)*4)+4

for j = 1 to times

'choose some dice values

dice = int(rnd(0)*6)+1

gosub [showDice1]

dice = int(rnd(0)*6)+1

gosub [showDice2]

'put a loop in here to pause for a brief moment (100 millisec)

t = time$("ms")

while time$("ms") < t + 100 : wend

next j

wait

[showDice1]

'clear graphicsbox contents release any used memory

"cls"

'Draw dice

if dice = 1 or dice = 3 or dice = 5 then

"up; goto 40 40;down; circlefilled 5"

end if

if dice > 1 then

"up; goto 15 15; down; circlefilled 5"
"up; goto 65 65; down; circlefilled 5"

end if

if dice > 3 then

"up; goto 65 15; down; circlefilled 5"
"up; goto 15 65; down; circlefilled 5"

end if

if dice = 6 then

"up; goto 15 40; down; circlefilled 5"
"up; goto 65 40; down; circlefilled 5"

end if

"flush"

return

[showDice2]

'clear graphicsbox contents release any used memory

"cls"

'Draw dice

if dice = 1 or dice = 3 or dice = 5 then

"up; goto 40 40;down; circlefilled 5"

end if

if dice > 1 then

"up; goto 15 15; down; circlefilled 5"
"up; goto 65 65; down; circlefilled 5"

end if

if dice > 3 then

"up; goto 65 15; down; circlefilled 5"
"up; goto 15 65; down; circlefilled 5"

end if

if dice = 6 then

"up; goto 15 40; down; circlefilled 5"
"up; goto 65 40; down; circlefilled 5"

end if

"flush"

return


Appendix B - The final GraphicCraps Program

'** Graphic Craps

'by Brad Moore, 2004 - in the public domain

'Main variable initialization

phase = 1 'this tracks whether we are rolling for a point (=1)

'or have established the point and rolling to win (=2)

wins = 0

losses = 0

'make the game truly random by seeding the generator

RANDOMIZE time$("ms")/86340000

NOMAINWIN

WindowWidth = 362

WindowHeight = 226

UpperLeftX = 40

UpperLeftY = 40

STATICTEXT #main.wins, "Wins: 0", 240, 14, 100, 20

STATICTEXT #main.losses, "Losses: 0", 240, 36, 100, 20

STATICTEXT #main.info, "Beginning New Round - Click to start", 18, 112, 200, 20

STATICTEXT #main.point, "Point has not been made yet", 18, 134, 200, 20

button #main.quit, "Quit",[quit],UL, 240, 160, 100, 25

button #main.help, "Help",[help],UL, 240, 130, 100, 25

button #main.about, "About",[about],UL, 240, 100, 100, 25

button #main.new, "New Game",[new],UL, 240, 70, 100, 25

button #main.roll, "Start Round",[roll],UL, 16, 160, 212, 25

graphicbox #main.dice1, 20, 20, 80, 80

graphicbox #main.dice2, 140, 20, 80, 80

Open "Graphic Craps" for window_nf as #main

"trapclose [quit]"

'format graphics boxes

"down; fill white; up; flush"
"down; fill white; up; flush"
"font ms_sans_serif 10"
"!font arial_narrow 10"
"!font arial_narrow 10"
"!font ms_sans_serif 10 bold"
"backcolor black"
"backcolor black"

Wait

[quit]

close #main : END

[roll]

'roll a random number of times

playwave "dice01.wav", async

times = int(rnd(0)*4)+4

for j = 1 to times

'choose some dice values

dice = int(rnd(0)*6)+1

total = dice

gosub [showDice1]

dice = int(rnd(0)*6)+1

total = total + dice

gosub [showDice2]

'put a loop in here to pause for a brief moment (100 millisec)

t = time$("ms")

while time$("ms") < t + 100 : wend

next j

'Now we have values for the dice - display the results...

if phase = 1 then

'if the phase is 1 then the point is not made

'check for instant loss (2, 3 or 12)

if total = 2 or total = 3 or total = 12 then

losses = losses + 1

"Losses = " + str$(losses)
"You rolled " + str$(total) + " - you crapped out!"
"Click Start to begin new round"

end if

'check for instant win (7 or 11)

if total = 7 or total = 11 then

wins = wins + 1

"Wins = " + str$(wins)
"You rolled " + str$(total) + " - you WIN instantly!"
"Click Start to begin new round"

end if

if total > 3 and total < 11 and total <> 7 then

'we have made a point - change the phase and note the point

"You made Point, click ROLL DICE to match"
"The point you are rolling for is " + str$(total)

phase = 2

point = total

"Roll Dice"

end if

else

'check for instant loss

if total = 7 then

losses = losses + 1

"Losses = " + str$(losses)
"You rolled " + str$(total) + " - you crapped out!"
"Click Start to begin new round"
"Start Round"

phase = 1

else

'check for win

if total = point then

wins = wins + 1

"Wins = " + str$(wins)
"You rolled " + str$(total) + " - you matched the point!"
"Thats a WIN - Click Start for new round"
"Start Round"

phase = 1

else

'this did not make point - roll again...

"You rolled " + str$(total) + " - you did not match the point"
"Roll Dice Again"

end if

end if

end if

wait

[showDice1]

'clear graphicsbox contents release any used memory

"cls"

'Draw dice

if dice = 1 or dice = 3 or dice = 5 then

"up; goto 40 40;down; circlefilled 5"

end if

if dice > 1 then

"up; goto 15 15; down; circlefilled 5"
"up; goto 65 65; down; circlefilled 5"

end if

if dice > 3 then

"up; goto 65 15; down; circlefilled 5"
"up; goto 15 65; down; circlefilled 5"

end if

if dice = 6 then

"up; goto 15 40; down; circlefilled 5"
"up; goto 65 40; down; circlefilled 5"

end if

return

[showDice2]

'clear graphicsbox contents release any used memory

"cls"

'Draw dice

if dice = 1 or dice = 3 or dice = 5 then

"up; goto 40 40;down; circlefilled 5"

end if

if dice > 1 then

"up; goto 15 15; down; circlefilled 5"
"up; goto 65 65; down; circlefilled 5"

end if

if dice > 3 then

"up; goto 65 15; down; circlefilled 5"
"up; goto 15 65; down; circlefilled 5"

end if

if dice = 6 then

"up; goto 15 40; down; circlefilled 5"
"up; goto 65 40; down; circlefilled 5"

end if

return

[about]

call aboutGC

wait

[help]

call helpGC

wait

[new]

confirm "Begin a New Game?" + chr$(13) + _

"This will reset win/loss results." + chr$(13) + _

"Are you sure you want to do this?"; answer$

if answer$ = "no" then wait

phase = 1

wins = 0

losses = 0

"Beginning New Game - Click to start"
"Point has not been made yet"
"Wins = 0"
"Losses = 0"
"Start Round"

wait

sub helpGC

a$ = "HELP for GraphicCraps..." + chr$(13)

a$ = a$ + "Here are the basic rules we will be using: Two dice are used." + chr$(13)

a$ = a$ + "Initial roll of the dice is to establish the 'point' which you" + chr$(13)

a$ = a$ + "will be trying to roll again. Rolling a 7 or 11 with your first" + chr$(13)

a$ = a$ + "roll is an automatic win. Rolling a 2, 3 or 12 with your initial" + chr$(13)

a$ = a$ + "roll is an automatic loss. An initial roll of 4, 5, 6, 8, 9 or" + chr$(13)

a$ = a$ + "10 establishes the 'point'." + chr$(13) + chr$(13)

a$ = a$ + "Once a point is established the player must roll the dice again" + chr$(13)

a$ = a$ + "(repeatedly until they win or lose). Rolling the 'point' again" + chr$(13)

a$ = a$ + "is a win. Rolling a 7 is a loss. Have fun!" + chr$(13)

notice a$

end sub

sub aboutGC

a$ = "About GraphicCraps..." + chr$(13)

a$ = a$ + "Graphic Craps - for Liberty Basic" + chr$(13)

a$ = a$ + "by Brad Moore, 2004" + chr$(13) + chr$(13)

a$ = a$ + "released into the Public Domain" + chr$(13) + chr$(13)

a$ = a$ + "Learn about Liberty Basic by visiting:" + chr$(13)

a$ = a$ + "http://www.libertybasic.com" + chr$(13) + chr$(13)

a$ = a$ + "See the Liberty Basic Newsletter online at:" + chr$(13)

a$ = a$ + "http://babek.info/libertybasicfiles/lbnews/" + chr$(13) + chr$(13)

a$ = a$ + "Have FUN!"

notice a$

end sub